package com.cyz.user.userService.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyz.common.bean.Card;
import com.cyz.common.bean.PathCard;
import com.cyz.user.userService.CardService;
import com.cyz.user.userService.PathCardService;
import com.cyz.common.mapper.PathCardMapper;
import com.cyz.common.utils.BeanCopyUtil;
import com.cyz.user.vo.PathCardVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 34928
* @description 针对表【path_card】的数据库操作Service实现
* @createDate 2023-03-01 09:50:15
*/
@Service
public class PathCardServiceImpl extends ServiceImpl<PathCardMapper, PathCard>
    implements PathCardService {

    @Autowired
    private CardService cardService;

    @Override
    public List<PathCardVo> getPathCardsByPathId(Integer id) {
        //条件筛选器
        LambdaQueryWrapper<PathCard> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //根据
        lambdaQueryWrapper.eq(PathCard::getPathId,id);
        List<PathCard> list = list(lambdaQueryWrapper);
        List<PathCardVo> pathCardVos = BeanCopyUtil.copyBeanList(list,PathCardVo.class);
        pathCardVos
                .forEach(item ->{
                    Card one = cardService.getById(item.getCardId());
                    String title = one.getTitle();
                    Integer id1 = one.getId();
                    item.setId(id1);
                    item.setTitle(title);
                });
        return pathCardVos;
    }
}




